<template>
	<view class="inwardAppoint">
		<uni-nav-bar color="#ffffff" background-color="#00aded" :statusBar="true" title="计次-运输需求" fixed="true" left-icon="left" left-text="返回" @clickLeft="back" />
		<view class="inwardAppoint_top">
			<!-- 搜索 -->
			<!-- 搜索 -->
			<dil-search :columnData="options.columnDataList" @onSearch="onSearch" v-if="options.columnDataList.length > 0"></dil-search>
		</view>
		<view class="inwardAppoint_main">
			<dil-card class="dilCard" @emitEvent="emitEvent" v-bind.sync="options"></dil-card>
		</view>
		<view class="poper">
			<uni-popup ref="poper" type="center" border-radius="10px 10px 0 0" background-color="#fff" style="width: 100%">
				<view class="poper_main" style="width: 95vw">
					<dil-Form formId="774" ref="form" v-model="formValue" class="dilForm" labelPosition="left" labelWidth="80px"></dil-Form>
				</view>
				<view class="poper_floot" style="text-align: center">
					<button type="warn" size="mini" style="margin: 10px" @click="closePopup">取消</button>
					<button type="primary" size="mini" style="margin: 10px" @click="editSubmit">提交</button>
				</view>
			</uni-popup>
		</view>
		<view class="poper">
			<uni-popup ref="poper" type="center" border-radius="10px 10px 0 0" background-color="#fff" style="width: 100%">
				<view class="poper_main" style="width: 95vw">
					<dil-Form formId="774" ref="form" v-model="formValue" class="dilForm" labelPosition="left" labelWidth="80px"></dil-Form>
				</view>
				<view class="poper_floot" style="text-align: center">
					<button type="warn" size="mini" style="margin: 10px" @click="closePopup">取消</button>
					<button type="primary" size="mini" style="margin: 10px" @click="editSubmit">提交</button>
				</view>
			</uni-popup>
		</view>
		<view class="inwardAppoint_floot"></view>
	</view>
</template>
<script>
import { mapState, mapMutations } from 'vuex';
export default {
	data() {
		return {
			options: {
				requestUrl: '/api/v1/ams/getProductPlanList?apiId=718',
				requestQuery: {},
				cardSlotList: [
					{
						label: '运输详情',
						icon: 'bars',
						emitEvent: 'transOrderDetails'
					},
					{
						label: '修改物料',
						icon: 'bars',
						emitEvent: 'updateMaterialInfo',
						noPre: '1'
					}
				],
				columnDataList: [],
				totalNum: 0
			},
			initialMap: {},
			businessTypeList: [],
			businessType: 0,
			formValue: {},
			currentItem: {}
		};
	},
	onShow() {
		this.getOrderSection();
	},
	mounted() {},
	methods: {
		updateMaterialInfo(item) {
			this.currentItem = item;
			this.$refs.poper.open();
		},
		closePopup(item) {
			this.currentItem = {};
			this.$refs.poper.close();
		},
		async editSubmit() {
			let data = {};
			data.operateFlag = '修改计次物料';
			data.transRequirementId = this.currentItem.transRequirementId;
			data.materialId = this.formValue.materialId;
			const res = await this.$myRequest({
				url: '/api/v1/tms/updCountResult',
				data: data
			}).catch((err) => {
				uni.showToast({
					title: err,
					duration: 2000,
					icon: 'error'
				});
			});
			if (res.data.status == 'succeed') {
				uni.showToast({
					title: res.data.message,
					duration: 2000,
					icon: 'success'
				});
				this.getOrderSection({});
			} else {
				uni.showToast({
					title: res.data.message,
					duration: 2000,
					icon: 'error'
				});
			}
		},
		getOrderSection(item = {}) {
			item.deleted = 4;
			item.jiCiRemark = '计次程序';
			this.options.requestQuery = JSON.parse(JSON.stringify(Object.assign(this.options.requestQuery, item)));
		},
		onSearch(item) {
			this.getOrderSection(item);
		},
		back() {
			uni.switchTab({
				url: '/pages/index/index'
			});
		},
		emitEvent(eventName, cardItem) {
			this[eventName](cardItem);
		},
		transOrderDetails(item) {
			uni.navigateTo({
				url:
					'/pages/transOrder/inwardTransOrder?params=' +
					JSON.stringify({
						requirementId: item.transRequirementId
					})
			});
		},
		//vuex
		...mapMutations('inward', ['updateInwardAppointItem'])
	}
};
</script>

<style lang="scss" scoped>
.inwardAppoint {
	width: 100vw;
	height: 100%;
	background-color: #f5f5f5;
	&_top {
		background-color: #fff;
	}
	&_main {
		.dilCard {
			margin-top: 5rpx;
		}
		.poper {
			.poper_main {
				margin-left: 10px;
				margin-top: 20px;
				display: flex;
				justify-content: center;
				align-items: center;
			}
		}
	}
	&_floot {
	}
	.pop {
		&_content {
			width: 90vw;
			height: 100%;
			background-color: #fff;
		}
	}
}
</style>
